<?php
/**
 * Unfuddle TicketReport Model
 * Ticket reports are a list of attributes that define a list of tickets
 *
 * @package     Unfuddle
 * @subpackage  Data Models
 * @author      Luke Visinoni <luke.visinoni@gmail.com>
 * @copyright   (c) 2010 Luke Visinoni <luke.visinoni@gmail.com>
 * @version     $Id: TicketReport.php 29 2011-05-09 07:08:53Z luke.visinoni $
 * @todo        This model should be highly specialized. It would be very
 *              convenient to be able to create a report using a fluid OOP
 *              interface using this class/object. Something like:
 *                  $report->select(array('id', 'summary', 'description', 'assignee', 'component'))
 *                      ->where('status eq ?', 'new')
 *                      ->where('assignee eq ?', 1)
 *                      ->order('assignee ASC');
 */
class Unfuddle_Model_TicketReport extends Unfuddle_Model_Abstract {

    const URI_TICKET_REPORTS = '/ticket_reports';
    
    const URI_PROJECT_TICKET_REPORTS = '/projects/{project_id}/ticket_reports';
    
    const URI_TICKET_REPORT_BY_ID = '/ticket_reports/{ticket_report_id}';
    
    const URI_PROJECT_TICKET_REPORT_BY_ID = '/projects/{project_id}/ticket_reports/{ticket_report_id}';
    
    const URI_TICKET_REPORT_GENERATE = '/ticket_reports/{ticket_report_id}/generate';
    
    const URI_PROJECT_TICKET_REPORT_GENERATE = '/projects/{project_id}/ticket_reports/{ticket_report_id}/generate';
    
    const URI_TICKET_REPORT_DYNAMIC = '/ticket_reports/{ticket_report_id}/dynamic';
    
    const URI_PROJECT_TICKET_REPORT_DYNAMIC = '/projects/{project_id}/ticket_reports/{ticket_report_id}/dynamic';
    
    /**
     * @var string Model name
     */
    protected $_name = 'ticket-report';
    
    /**
     * @var array Model fields
     */
    protected $_fields = array (
        /**
         * A comma or vertical bar separated list of report criteria composed as 
         *   "field-expr-value, field-expr-value | field-expr-value"
         *   
         *   "field" is one of the following: [number, summary, priority, status, resolution, milestone, component, version, severity, reporter, assignee, created_at, updated_at, last_comment_at, due_on, field_1, field_2, field_3]
         *   "expr" is one of the following: [eq, neq, gt, lt, gteq, lteq]
         *   "value" is an appropriate value for the given field; "value" can also be "current" for fields that represent people.
         * 
         * Note: The comma acts as the AND operator and the vertical bar as the OR operator
         * Example: "assignee-eq-current,status-eq-closed|status-eq-resolved,milestone-eq-34584"
         *            translates into
         *          Assignee is the Current user AND (Status is Closed OR Status is Resolved) AND Milestone is 34584
         */
        'conditions-string' => array('type' => 'text', 'required' => false, 'read-only' => false),
        'created-at' => array('type' => 'datetime', 'required' => false, 'read-only' => true),
        /**
         * A comma separated list composed of any or all of the following:
         * [project, number, summary, priority, component, version, severity, milestone, due_on, reporter, assignee, status, resolution, comments, associations, hours_estimate_initial, hours_estimate_current, hours_actual, percentage_complete, created_at, updated_at, closed_on, field_1, field_2, field_3]    
         */
        'fields-string' => array('type' => 'text', 'required' => false, 'read-only' => false),
        'group-by' => array('type' => 'set', 'required' => false, 'read-only' => false, 'set' => array('project', 'priority', 'component', 'version', 'severity', 'milestone', 'due_on', 'reporter', 'assignee', 'status', 'resolution', 'field_1', 'field_2', 'field_3')),
        'id' => array('type' => 'integer', 'required' => false, 'read-only' => true),
        'parent-id' => array('type' => 'integer', 'required' => false, 'read-only' => true),
        'parent-type' => array('type' => 'set', 'required' => false, 'read-only' => true, 'set' => array('account', 'project')),
        'sort-by' => array('type' => 'text', 'required' => false, 'read-only' => false),
        'sort-direction' => array('type' => 'set', 'required' => false, 'read-only' => false, 'set' => array('asc', 'desc')),
        'title' => array('type' => 'text', 'required' => false, 'read-only' => false),
        'updated-at' => array('type' => 'datetime', 'required' => false, 'read-only' => true),
    );
    
    /**
     * If you 'generate' the report, then the following section will also
     * be available in the response.
     * @todo Figure out how to handle this...
            <groups>
              <group>
                <title> </title>
                <tickets>
                  <ticket> ... </ticket>
                  ...
                </tickets>
              </group>
              ...
            </groups>
     */
    protected $_children = array('groups');

}
